Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
How can i ignore "n\" in javascript

so what i wanna do is, i have some text, and when i click some word, it returns me that word. So let's say ' I have a car ', if i click 'car', i want it to return me 'car'. To do that, i tried this:

const alltext = text.toLowerCase().split(" ");

text is the target text (it would be the 'i have a car').

So now i have an array with each word. To render it i did:

alltext.map((item) => (
          <span> {item}</span>
        )) 

And i passed a click function that returns to me the span inner text. And it's working ok most of times, the problem is if i paste a text with two paragraphs, because that blank line becomes '\n' in the array. So if i have like

The american history.

It begins with...

And i paste it, the array is ['the', 'american', 'history.\n\nit', 'begins', 'with']

Allthough it renders decently, the problem is when i click history, it returns 'history. it'. First of all, is there a better/smarter way to do that? And second, how can i fix this?

Thank you

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!